package me.leiusual.sharing.ui.store

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.StoreDetail
import me.leiusual.sharing.pref.Store
import me.leiusual.sharing.repository.StoreRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/15
 */
class StoreHomeViewModel @Inject constructor(
    private val storeRepository: StoreRepository,
    val store: Store
) : ViewModel() {

  // 店铺信息

  private val _storeDetail = MutableLiveData<Long>()
  val storeDetail: LiveData<Data<StoreDetail.Response>> = switchMap(_storeDetail) {
    storeRepository.storeDetail(it).toLiveData()
  }

  fun storeDetail(storeId: Long) {
    _storeDetail.value = storeId
  }
}